package com.free.semantic.core.businessfunction.impl;

import com.free.semantic.common.Ls;
import com.free.semantic.common.RangeObj;
import com.free.semantic.core.Context;
import com.free.semantic.core.businessfunction.BasicFunction;
import com.free.semantic.core.businessfunction.ObjectConst;
import com.google.common.collect.Lists;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class UserToHabit implements BasicFunction {

    Map<String, List<String>> testData = new HashMap<>();

    @PostConstruct
    public void init() {
        testData.put("逍遥游", Ls.of("1", "2"));
    }

    @Override
    public List<RangeObj> require() {
        return Lists.newArrayList(RangeObj.one(ObjectConst.USER));
    }

    @Override
    public RangeObj provider() {
        return RangeObj.one(ObjectConst.HABIT);
    }

    @Override
    public void calculate(Context context) {
        List<String> listValue = context.getListValue(ObjectConst.USER);
        List<String> allHabits = testData.get(listValue.get(0));
        context.setValue(ObjectConst.HABIT, allHabits);
    }
}
